<template>
  <div>
    <vab-query-form>
      <vab-query-form-left-panel>
        <el-button icon="el-icon-plus" type="primary" @click="dialogFormVisible = true">
          添加
        </el-button>
        <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
          删除
        </el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel>
        <el-form ref="form" :model="queryForm" :inline="true" @submit.native.prevent>
          <el-form-item>
            <el-input v-model="queryForm.informationIntention" placeholder="班级名称" />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" native-type="submit" @click="handleQuery">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-table ref="multipleTable" :data="clazzs" tooltip-effect="dark" style="width: 100%" v-loading="listLoading"
      :element-loading-text="elementLoadingText" @selection-change="handleSelectionChange">
      <el-table-column show-overflow-tooltip type="selection" width="55"></el-table-column>
      <el-table-column prop="clazzId" label="班级编号">
      </el-table-column>
      <el-table-column prop="clazzName" label="班级姓名">
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间">
      </el-table-column>
      <!--      <el-table-column prop="informationImg" label="简历个人照片">
        <template slot-scope="scope">
          <img v-if="scope.row.informationImg" :src="scope.row.informationImg" width="50px" height="50px">
        </template>
      </el-table-column> -->
      <el-table-column prop="clazzType" label="班级类型" :formatter="Sexformatter">
      </el-table-column>

      <el-table-column show-overflow-tooltip label="操作" width="180px">
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">修改状态</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination :background="background" :current-page="queryForm.current" :layout="layout"
      :page-size="queryForm.size" :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange">
    </el-pagination>
    <div>
      <el-dialog title="新建班级" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="班级名称" :label-width="formLabelWidth">
            <el-input v-model="form.clazzName" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="班级类型" :label-width="formLabelWidth">
            <el-select v-model="form.clazzType" placeholder="请选择活动区域">
              <el-option label="上午班" value="1"></el-option>
              <el-option label="下午班" value="2"></el-option>
              <el-option label="晚班" value="3"></el-option>
              <el-option label="周末班" value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
        </div>
      </el-dialog>
    </div>

  </div>
</template>

<script>
  import {
    getClazzByCollageId
  } from '@/api/student.js'
  export default {
    name: 'clazzs',
    data() {
      return {
        formLabelWidth: '120px',
        form: {},
        dialogFormVisible: false,
        collageId: 0,
        clazzs: [],
        pages: 0,
        layout: 'total, sizes, prev, pager, next, jumper',
        background: true,
        multipleSelection: [],
        listLoading: true,
        elementLoadingText: '正在加载...',
        total: 0,
        queryForm: {
          current: 1,
          size: 10,
          paramMap: {
            collageId: ''
          },
        },
      }
    },
    computed: {

      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      //学院ID
      window.sessionStorage.setItem("schoolId", "1440285428262379522");
      this.queryForm.paramMap.collageId = window.sessionStorage.getItem("schoolId");
    },
    mounted() {
      this.queryForm.paramMap.collageId = window.sessionStorage.getItem("schoolId")
      console.log("schooleId:", this.queryForm.paramMap.collageId)
      getClazzByCollageId(this.queryForm).then(data => {
        if (data.code == 200) {
          this.listLoading = false
          this.clazzs = data.data.records
          this.total = parseInt(data.data.total)
          this.queryForm.size = parseInt(data.data.size)
          this.queryForm.current = parseInt(data.data.current)

        } else {
          this.$baseMessage(data.msg, 'error')
        }
      })

    },
    methods: {
      Sexformatter(row) {
        console.log(row)
        if (row.clazzType == 1) {
          return "上午班"
        } else if (row.clazzType == 2) {
          return "下午班"
        } else if (row.clazzType == 3) {
          return "晚班"
        } else {
          return "周末班"
        }
      },

      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //添加
      handleAdd() {

      },
      //编辑 开启隐藏页面 赋值
      handleEdit(row) {

      },
      handleDelete() {

      },
      //页面改变
      handleSizeChange(val) {
        this.queryForm.size = val
        this.queryForm.paramMap.collageId = window.sessionStorage.getItem("schoolId")
        console.log("schooleId:", this.queryForm.paramMap.collageId)
        getClazzByCollageId(this.queryForm).then(data => {
          if (data.code == 200) {
            this.listLoading = false
            this.clazzs = data.data.records
            this.total = parseInt(data.data.total)
            this.queryForm.size = parseInt(data.data.size)
            this.queryForm.current = parseInt(data.data.current)

          } else {
            this.$baseMessage(data.msg, 'error')
          }
        })
      },
      handleCurrentChange(val) {
        this.queryForm.current = val
        this.queryForm.paramMap.collageId = window.sessionStorage.getItem("schoolId")
        console.log("schooleId:", this.queryForm.paramMap.collageId)
        getClazzByCollageId(this.queryForm).then(data => {
          if (data.code == 200) {
            this.listLoading = false
            this.clazzs = data.data.records
            this.total = parseInt(data.data.total)
            this.queryForm.size = parseInt(data.data.size)
            this.queryForm.current = parseInt(data.data.current)

          } else {
            this.$baseMessage(data.msg, 'error')
          }
        })
      },
    }
  }
</script>

<style>
</style>
